package com.yunxin.admin.system.infra.persistence.repository;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yunxin.admin.system.domain.model.dict.DictType;
import com.yunxin.admin.system.domain.model.dict.DictTypeRepository;
import com.yunxin.admin.system.infra.persistence.converter.DictTypeConverter;
import com.yunxin.admin.system.infra.persistence.entity.SysDictTypeDO;
import com.yunxin.admin.system.infra.persistence.mapper.SysDictTypeMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.List;

/**
 * @author zero°
 * @since 2023-07-11
 */
@Repository
@RequiredArgsConstructor
public class DictTypeRepositoryImpl extends ServiceImpl<SysDictTypeMapper, SysDictTypeDO> implements DictTypeRepository, IService<SysDictTypeDO> {

    private final DictTypeConverter dictTypeConverter;

    @Override
    public boolean saveDictType(DictType dictType) {
        SysDictTypeDO sysDictTypeDO = dictTypeConverter.fromDictType(dictType);
        return this.save(sysDictTypeDO);
    }

    @Override
    public boolean updateDictType(DictType dictType) {
        SysDictTypeDO sysDictTypeDO = dictTypeConverter.fromDictType(dictType);
        return this.updateById(sysDictTypeDO);
    }

    @Override
    public boolean removeByIdList(Collection<Long> ids) {
        return false;
    }

    @Override
    public DictType getDictTypeById(Long id) {
        SysDictTypeDO sysDictTypeDO = this.getById(id);
        return dictTypeConverter.toDictType(sysDictTypeDO);
    }

    @Override
    public List<String> listDictTypeCodeByIds(Collection<Long> ids) {
        return this.list(new LambdaQueryWrapper<SysDictTypeDO>()
                        .in(SysDictTypeDO::getId, ids)
                        .select(SysDictTypeDO::getCode))
                .stream().map(SysDictTypeDO::getCode).toList();
    }
}
